// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0612, CS0618

namespace System.Runtime.CompilerServices
{
    using System;
    using System.CodeDom.Compiler;

    [GeneratedCode("Microsoft.Extensions.Configuration.Binder.SourceGeneration", "42.42.42.42")]
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
    file sealed class InterceptsLocationAttribute : Attribute
    {
        public InterceptsLocationAttribute(string filePath, int line, int column)
        {
        }
    }
}

namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration
{
    using Microsoft.Extensions.Configuration;
    using System;
    using System.CodeDom.Compiler;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Runtime.CompilerServices;

    [GeneratedCode("Microsoft.Extensions.Configuration.Binder.SourceGeneration", "42.42.42.42")]
    file static class BindingExtensions
    {
        #region IConfiguration extensions.
        /// <summary>Attempts to bind the given object instance to configuration values by matching property names against configuration keys recursively.</summary>
        [InterceptsLocation(@"src-0.cs", 13, 16)]
        public static void Bind_ProgramMyClass(this IConfiguration configuration, object? instance)
        {
            if (configuration is null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (instance is null)
            {
                return;
            }

            var typedObj = (global::Program.MyClass)instance;
            BindCore(configuration, ref typedObj, defaultValueIfNotFound: false, binderOptions: null);
        }
        #endregion IConfiguration extensions.

        #region Core binding extensions.
        private readonly static Lazy<HashSet<string>> s_configKeys_ProgramMyClass = new(() => new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Prop0", "Prop1", "Prop2", "Prop3", "Prop4", "Prop5", "Prop6", "Prop8", "Prop9", "Prop10", "Prop13", "Prop14", "Prop15", "Prop16", "Prop17", "Prop19", "Prop20", "Prop21", "Prop23", "Prop24", "Prop25", "Prop26", "Prop27", "Prop28", "Prop29", "Prop30" });

        public static void BindCore(IConfiguration configuration, ref global::Program.MyClass instance, bool defaultValueIfNotFound, BinderOptions? binderOptions)
        {
            ValidateConfigurationKeys(typeof(global::Program.MyClass), s_configKeys_ProgramMyClass, configuration, binderOptions);

            if (configuration["Prop0"] is string value0)
            {
                instance.Prop0 = ParseBool(value0, () => configuration.GetSection("Prop0").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop0 = default;
            }

            if (configuration["Prop1"] is string value1)
            {
                instance.Prop1 = ParseByte(value1, () => configuration.GetSection("Prop1").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop1 = default;
            }

            if (configuration["Prop2"] is string value2)
            {
                instance.Prop2 = ParseSbyte(value2, () => configuration.GetSection("Prop2").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop2 = default;
            }

            if (configuration["Prop3"] is string value3)
            {
                instance.Prop3 = ParseChar(value3, () => configuration.GetSection("Prop3").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop3 = default;
            }

            if (configuration["Prop4"] is string value4)
            {
                instance.Prop4 = ParseDouble(value4, () => configuration.GetSection("Prop4").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop4 = default;
            }

            if (configuration["Prop5"] is string value5)
            {
                instance.Prop5 = value5;
            }

            if (configuration["Prop6"] is string value6)
            {
                instance.Prop6 = ParseInt(value6, () => configuration.GetSection("Prop6").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop6 = default;
            }

            if (configuration["Prop8"] is string value7)
            {
                instance.Prop8 = ParseShort(value7, () => configuration.GetSection("Prop8").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop8 = default;
            }

            if (configuration["Prop9"] is string value8)
            {
                instance.Prop9 = ParseLong(value8, () => configuration.GetSection("Prop9").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop9 = default;
            }

            if (configuration["Prop10"] is string value9)
            {
                instance.Prop10 = ParseFloat(value9, () => configuration.GetSection("Prop10").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop10 = default;
            }

            if (configuration["Prop13"] is string value10)
            {
                instance.Prop13 = ParseUshort(value10, () => configuration.GetSection("Prop13").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop13 = default;
            }

            if (configuration["Prop14"] is string value11)
            {
                instance.Prop14 = ParseUint(value11, () => configuration.GetSection("Prop14").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop14 = default;
            }

            if (configuration["Prop15"] is string value12)
            {
                instance.Prop15 = ParseUlong(value12, () => configuration.GetSection("Prop15").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop15 = default;
            }

            if (configuration["Prop16"] is string value13)
            {
                instance.Prop16 = value13;
            }

            if (configuration["Prop17"] is string value14)
            {
                instance.Prop17 = ParseSystemGlobalizationCultureInfo(value14, () => configuration.GetSection("Prop17").Path);
            }

            if (configuration["Prop19"] is string value15)
            {
                instance.Prop19 = ParseSystemDateTime(value15, () => configuration.GetSection("Prop19").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop19 = default;
            }

            if (configuration["Prop20"] is string value16)
            {
                instance.Prop20 = ParseSystemDateTimeOffset(value16, () => configuration.GetSection("Prop20").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop20 = default;
            }

            if (configuration["Prop21"] is string value17)
            {
                instance.Prop21 = ParseDecimal(value17, () => configuration.GetSection("Prop21").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop21 = default;
            }

            if (configuration["Prop23"] is string value18)
            {
                instance.Prop23 = ParseSystemTimeSpan(value18, () => configuration.GetSection("Prop23").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop23 = default;
            }

            if (configuration["Prop24"] is string value19)
            {
                instance.Prop24 = ParseSystemGuid(value19, () => configuration.GetSection("Prop24").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop24 = default;
            }

            if (configuration["Prop25"] is string value20)
            {
                instance.Prop25 = ParseSystemUri(value20, () => configuration.GetSection("Prop25").Path);
            }

            if (configuration["Prop26"] is string value21)
            {
                instance.Prop26 = ParseSystemVersion(value21, () => configuration.GetSection("Prop26").Path);
            }

            if (configuration["Prop27"] is string value22)
            {
                instance.Prop27 = ParseEnum<global::System.DayOfWeek>(value22, () => configuration.GetSection("Prop27").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop27 = default;
            }

            if (configuration["Prop28"] is string value23)
            {
                instance.Prop28 = ParseByteArray(value23, () => configuration.GetSection("Prop28").Path);
            }

            if (configuration["Prop29"] is string value24)
            {
                instance.Prop29 = ParseInt(value24, () => configuration.GetSection("Prop29").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop29 = default;
            }

            if (configuration["Prop30"] is string value25)
            {
                instance.Prop30 = ParseSystemDateTime(value25, () => configuration.GetSection("Prop30").Path);
            }
            else if (defaultValueIfNotFound)
            {
                instance.Prop30 = default;
            }
        }


        /// <summary>If required by the binder options, validates that there are no unknown keys in the input configuration object.</summary>
        public static void ValidateConfigurationKeys(Type type, Lazy<HashSet<string>> keys, IConfiguration configuration, BinderOptions? binderOptions)
        {
            if (binderOptions?.ErrorOnUnknownConfiguration is true)
            {
                List<string>? temp = null;
        
                foreach (IConfigurationSection section in configuration.GetChildren())
                {
                    if (!keys.Value.Contains(section.Key))
                    {
                        (temp ??= new List<string>()).Add($"'{section.Key}'");
                    }
                }
        
                if (temp is not null)
                {
                    throw new InvalidOperationException($"'ErrorOnUnknownConfiguration' was set on the provided BinderOptions, but the following properties were not found on the instance of {type}: {string.Join(", ", temp)}");
                }
            }
        }

        public static T ParseEnum<T>(string value, Func<string?> getPath) where T : struct
        {
            try
            {
                return (T)Enum.Parse(typeof(T), value, ignoreCase: true);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(T)}'.", exception);
            }
        }

        public static bool ParseBool(string value, Func<string?> getPath)
        {
            try
            {
                return bool.Parse(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(bool)}'.", exception);
            }
        }

        public static byte ParseByte(string value, Func<string?> getPath)
        {
            try
            {
                return byte.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(byte)}'.", exception);
            }
        }

        public static sbyte ParseSbyte(string value, Func<string?> getPath)
        {
            try
            {
                return sbyte.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(sbyte)}'.", exception);
            }
        }

        public static char ParseChar(string value, Func<string?> getPath)
        {
            try
            {
                return char.Parse(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(char)}'.", exception);
            }
        }

        public static double ParseDouble(string value, Func<string?> getPath)
        {
            try
            {
                return double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(double)}'.", exception);
            }
        }

        public static int ParseInt(string value, Func<string?> getPath)
        {
            try
            {
                return int.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(int)}'.", exception);
            }
        }

        public static short ParseShort(string value, Func<string?> getPath)
        {
            try
            {
                return short.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(short)}'.", exception);
            }
        }

        public static long ParseLong(string value, Func<string?> getPath)
        {
            try
            {
                return long.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(long)}'.", exception);
            }
        }

        public static float ParseFloat(string value, Func<string?> getPath)
        {
            try
            {
                return float.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(float)}'.", exception);
            }
        }

        public static ushort ParseUshort(string value, Func<string?> getPath)
        {
            try
            {
                return ushort.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(ushort)}'.", exception);
            }
        }

        public static uint ParseUint(string value, Func<string?> getPath)
        {
            try
            {
                return uint.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(uint)}'.", exception);
            }
        }

        public static ulong ParseUlong(string value, Func<string?> getPath)
        {
            try
            {
                return ulong.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(ulong)}'.", exception);
            }
        }

        public static global::System.Globalization.CultureInfo ParseSystemGlobalizationCultureInfo(string value, Func<string?> getPath)
        {
            try
            {
                return CultureInfo.GetCultureInfo(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Globalization.CultureInfo)}'.", exception);
            }
        }

        public static global::System.DateTime ParseSystemDateTime(string value, Func<string?> getPath)
        {
            try
            {
                return global::System.DateTime.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.DateTime)}'.", exception);
            }
        }

        public static global::System.DateTimeOffset ParseSystemDateTimeOffset(string value, Func<string?> getPath)
        {
            try
            {
                return global::System.DateTimeOffset.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.DateTimeOffset)}'.", exception);
            }
        }

        public static decimal ParseDecimal(string value, Func<string?> getPath)
        {
            try
            {
                return decimal.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(decimal)}'.", exception);
            }
        }

        public static global::System.TimeSpan ParseSystemTimeSpan(string value, Func<string?> getPath)
        {
            try
            {
                return global::System.TimeSpan.Parse(value, CultureInfo.InvariantCulture);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.TimeSpan)}'.", exception);
            }
        }

        public static global::System.Guid ParseSystemGuid(string value, Func<string?> getPath)
        {
            try
            {
                return global::System.Guid.Parse(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Guid)}'.", exception);
            }
        }

        public static global::System.Uri ParseSystemUri(string value, Func<string?> getPath)
        {
            try
            {
                return new Uri(value, UriKind.RelativeOrAbsolute);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Uri)}'.", exception);
            }
        }

        public static global::System.Version ParseSystemVersion(string value, Func<string?> getPath)
        {
            try
            {
                return global::System.Version.Parse(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(global::System.Version)}'.", exception);
            }
        }

        public static byte[] ParseByteArray(string value, Func<string?> getPath)
        {
            try
            {
                return Convert.FromBase64String(value);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Failed to convert configuration value at '{getPath()}' to type '{typeof(byte[])}'.", exception);
            }
        }
        #endregion Core binding extensions.
    }
}
